1 // -*- C++ -*- C forwarding header.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 26.5 C library
36 * This is a Standard C++ Library file. You should @c #include this file
37 * in your programs, rather than any of the "*.h" implementation files.
39 * This is the C++ version of the Standard C Library header @c math.h,
40 * and its contents are (mostly) the same as that header, but are all
41 * contained in the namespace @c std (except for names which are defined
45 #ifndef _GLIBCXX_CMATH
46 #define _GLIBCXX_CMATH 1
48 #pragma GCC system_header
50 #include <bits/c++config.h>
51 #include <bits/cpp_type_traits.h>
55 // Get rid of those macros defined in <math.h> in lieu of real functions.
84 // Forward declaration of a helper function. This really should be
85 // an `exported' forward declaration.
86 template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
90 { return __builtin_fabs(__x); }
94 { return __builtin_fabsf(__x); }
98 { return __builtin_fabsl(__x); }
104 { return __builtin_acosf(__x); }
107 acos(long double __x)
108 { return __builtin_acosl(__x); }
110 template<typename _Tp>
111 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
114 return __builtin_acos(__x);
121 { return __builtin_asinf(__x); }
124 asin(long double __x)
125 { return __builtin_asinl(__x); }
127 template<typename _Tp>
128 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
130 { return __builtin_asin(__x); }
136 { return __builtin_atanf(__x); }
139 atan(long double __x)
140 { return __builtin_atanl(__x); }
142 template<typename _Tp>
143 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
145 { return __builtin_atan(__x); }
150 atan2(float __y, float __x)
151 { return __builtin_atan2f(__y, __x); }
154 atan2(long double __y, long double __x)
155 { return __builtin_atan2l(__y, __x); }
157 template<typename _Tp, typename _Up>
158 inline typename __enable_if<double, __is_integer<_Tp>::__value
159 && __is_integer<_Up>::__value>::__type
160 atan2(_Tp __y, _Up __x)
161 { return __builtin_atan2(__y, __x); }
167 { return __builtin_ceilf(__x); }
170 ceil(long double __x)
171 { return __builtin_ceill(__x); }
173 template<typename _Tp>
174 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
176 { return __builtin_ceil(__x); }
182 { return __builtin_cosf(__x); }
186 { return __builtin_cosl(__x); }
188 template<typename _Tp>
189 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
191 { return __builtin_cos(__x); }
197 { return __builtin_coshf(__x); }
200 cosh(long double __x)
201 { return __builtin_coshl(__x); }
203 template<typename _Tp>
204 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
206 { return __builtin_cosh(__x); }
212 { return __builtin_expf(__x); }
216 { return __builtin_expl(__x); }
218 template<typename _Tp>
219 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
221 { return __builtin_exp(__x); }
227 { return __builtin_fabsf(__x); }
230 fabs(long double __x)
231 { return __builtin_fabsl(__x); }
233 template<typename _Tp>
234 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
236 { return __builtin_fabs(__x); }
242 { return __builtin_floorf(__x); }
245 floor(long double __x)
246 { return __builtin_floorl(__x); }
248 template<typename _Tp>
249 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
251 { return __builtin_floor(__x); }
256 fmod(float __x, float __y)
257 { return __builtin_fmodf(__x, __y); }
260 fmod(long double __x, long double __y)
261 { return __builtin_fmodl(__x, __y); }
266 frexp(float __x, int* __exp)
267 { return __builtin_frexpf(__x, __exp); }
270 frexp(long double __x, int* __exp)
271 { return __builtin_frexpl(__x, __exp); }
273 template<typename _Tp>
274 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
275 frexp(_Tp __x, int* __exp)
276 { return __builtin_frexp(__x, __exp); }
281 ldexp(float __x, int __exp)
282 { return __builtin_ldexpf(__x, __exp); }
285 ldexp(long double __x, int __exp)
286 { return __builtin_ldexpl(__x, __exp); }
288 template<typename _Tp>
289 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
290 ldexp(_Tp __x, int __exp)
291 { return __builtin_ldexp(__x, __exp); }
297 { return __builtin_logf(__x); }
301 { return __builtin_logl(__x); }
303 template<typename _Tp>
304 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
306 { return __builtin_log(__x); }
312 { return __builtin_log10f(__x); }
315 log10(long double __x)
316 { return __builtin_log10l(__x); }
318 template<typename _Tp>
319 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
321 { return __builtin_log10(__x); }
326 modf(float __x, float* __iptr)
327 { return __builtin_modff(__x, __iptr); }
330 modf(long double __x, long double* __iptr)
331 { return __builtin_modfl(__x, __iptr); }
333 template<typename _Tp>
335 __pow_helper(_Tp __x, int __n)
338 ? _Tp(1)/__cmath_power(__x, -__n)
339 : __cmath_power(__x, __n);
345 pow(float __x, float __y)
346 { return __builtin_powf(__x, __y); }
349 pow(long double __x, long double __y)
350 { return __builtin_powl(__x, __y); }
353 pow(double __x, int __i)
354 { return __builtin_powi(__x, __i); }
357 pow(float __x, int __n)
358 { return __builtin_powif(__x, __n); }
361 pow(long double __x, int __n)
362 { return __builtin_powil(__x, __n); }
368 { return __builtin_sinf(__x); }
372 { return __builtin_sinl(__x); }
374 template<typename _Tp>
375 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
377 { return __builtin_sin(__x); }
383 { return __builtin_sinhf(__x); }
386 sinh(long double __x)
387 { return __builtin_sinhl(__x); }
389 template<typename _Tp>
390 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
392 { return __builtin_sinh(__x); }
398 { return __builtin_sqrtf(__x); }
401 sqrt(long double __x)
402 { return __builtin_sqrtl(__x); }
404 template<typename _Tp>
405 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
407 { return __builtin_sqrt(__x); }
413 { return __builtin_tanf(__x); }
417 { return __builtin_tanl(__x); }
419 template<typename _Tp>
420 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
422 { return __builtin_tan(__x); }
428 { return __builtin_tanhf(__x); }
431 tanh(long double __x)
432 { return __builtin_tanhl(__x); }
434 template<typename _Tp>
435 inline typename __enable_if<double, __is_integer<_Tp>::__value>::__type
437 { return __builtin_tanh(__x); }
440 #if _GLIBCXX_USE_C99_MATH
441 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
442 // These are possible macros imported from C99-land. For strict
443 // conformance, remove possible C99-injected names from the global
444 // namespace, and sequester them in the __gnu_cxx extension namespace.
447 template<typename _Tp>
449 __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
451 template<typename _Tp>
453 __capture_isfinite(_Tp __f) { return isfinite(__f); }
455 template<typename _Tp>
457 __capture_isinf(_Tp __f) { return isinf(__f); }
459 template<typename _Tp>
461 __capture_isnan(_Tp __f) { return isnan(__f); }
463 template<typename _Tp>
465 __capture_isnormal(_Tp __f) { return isnormal(__f); }
467 template<typename _Tp>
469 __capture_signbit(_Tp __f) { return signbit(__f); }
471 template<typename _Tp>
473 __capture_isgreater(_Tp __f1, _Tp __f2)
474 { return isgreater(__f1, __f2); }
476 template<typename _Tp>
478 __capture_isgreaterequal(_Tp __f1, _Tp __f2)
479 { return isgreaterequal(__f1, __f2); }
481 template<typename _Tp>
483 __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
485 template<typename _Tp>
487 __capture_islessequal(_Tp __f1, _Tp __f2)
488 { return islessequal(__f1, __f2); }
490 template<typename _Tp>
492 __capture_islessgreater(_Tp __f1, _Tp __f2)
493 { return islessgreater(__f1, __f2); }
495 template<typename _Tp>
497 __capture_isunordered(_Tp __f1, _Tp __f2)
498 { return isunordered(__f1, __f2); }
501 // Only undefine the C99 FP macros, if actually captured for namespace movement
509 #undef isgreaterequal
517 template<typename _Tp>
519 fpclassify(_Tp __f) { return __gnu_cxx::__capture_fpclassify(__f); }
521 template<typename _Tp>
523 isfinite(_Tp __f) { return __gnu_cxx::__capture_isfinite(__f); }
525 template<typename _Tp>
527 isinf(_Tp __f) { return __gnu_cxx::__capture_isinf(__f); }
529 template<typename _Tp>
531 isnan(_Tp __f) { return __gnu_cxx::__capture_isnan(__f); }
533 template<typename _Tp>
535 isnormal(_Tp __f) { return __gnu_cxx::__capture_isnormal(__f); }
537 template<typename _Tp>
539 signbit(_Tp __f) { return __gnu_cxx::__capture_signbit(__f); }
541 template<typename _Tp>
543 isgreater(_Tp __f1, _Tp __f2)
544 { return __gnu_cxx::__capture_isgreater(__f1, __f2); }
546 template<typename _Tp>
548 isgreaterequal(_Tp __f1, _Tp __f2)
549 { return __gnu_cxx::__capture_isgreaterequal(__f1, __f2); }
551 template<typename _Tp>
553 isless(_Tp __f1, _Tp __f2)
554 { return __gnu_cxx::__capture_isless(__f1, __f2); }
556 template<typename _Tp>
558 islessequal(_Tp __f1, _Tp __f2)
559 { return __gnu_cxx::__capture_islessequal(__f1, __f2); }
561 template<typename _Tp>
563 islessgreater(_Tp __f1, _Tp __f2)
564 { return __gnu_cxx::__capture_islessgreater(__f1, __f2); }
566 template<typename _Tp>
568 isunordered(_Tp __f1, _Tp __f2)
569 { return __gnu_cxx::__capture_isunordered(__f1, __f2); }
571 #endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
574 #ifndef _GLIBCXX_EXPORT_TEMPLATE
575 # include <bits/cmath.tcc>